package com.zhou.controller;

import com.zhou.dto.integral.IntegralDTO;
import com.zhou.result.R;
import com.zhou.service.IntegralService;
import com.zhou.utils.APPApplicationException;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description : 积分
 * @Author : zyy
 * @Date: 2024/6/19  16:16
 */
@RestController
@RequestMapping("/integral")
@Slf4j
@Api(tags = "积分")
public class IntegralController {

    @Autowired
    private IntegralService integralService;
    /**
     * 新增积分
     */
    @PostMapping("/add")
    @Operation(summary = "新增积分")
    public R add(@RequestBody IntegralDTO dto) {
       try {
           return R.success(integralService.add(dto));
       }catch (APPApplicationException e) {
           return R.error(e.getMessage());
       }
    }

    /**
     * 分页查询积分
     * @param page 1
     * @param pageSize 10
     * @return 积分集合
     */
    @GetMapping ("/list")
    @Operation(summary = "分页查询积分")
    public R list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize) {
        try {
            return R.success(integralService.list(page,pageSize));
        }catch (APPApplicationException e) {
            return R.error(e.getMessage());
        }
    }

    @PutMapping("/update/status")
    @Operation(summary = "修改积分状态")
    public R updateStatus(@RequestParam String integralId) {
        try {
            return R.success(integralService.updateStatus(integralId));
        }catch (APPApplicationException e) {
            return R.error(e.getMessage());
        }
    }
}
